<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/layouts/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>创建帮助内容</title>
    <%@include file="/WEB-INF/layouts/edit-header.jsp" %>

    <%--select--%>
    <link rel="stylesheet" type="text/css" href="${staticPath}/select/css/bootstrap-drilldown-select.css">
    <%--select--%>

    <script type="text/javascript">
        var _ctx = '${ctx}';
        var _staticPath = '${staticPath}';
    </script>

    <%--neditor--%>
    <script type="text/javascript" charset="utf-8" src="${staticPath}/neditor/neditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${staticPath}/neditor/_examples/editor_api.js"></script>
    <script type="text/javascript" charset="utf-8" src="${staticPath}/neditor/lang/zh-cn/zh-cn.js"></script>

    <%--select--%>
    <script src="${staticPath}/select/js/bootstrap-drilldown-select.js"></script>
    <script src="${staticPath}/admin/tcsf/wg_listToTree1.1.js"></script>
    <%--select--%>

    <style type="text/css">
        div {
            width: 100%;
        }

        .dropdown-menu {
            z-index: 99999999999 !important;
        }

    </style>
</head>
<body>
<div class="tpanel">
    <div class="panel-content">
        <div class="container-fluid">
            <div class="ibox-content" style="padding-top:50px;">
                <form id="createForm" class="form-horizontal">

                    <div class="form-group form-group-first">
                        <label for="title" class="col-sm-2 control-label">文章标题</label>
                        <div class="col-sm-8 ">
                            <input type="text" class="form-control" id="title" name="title"
                                   placeholder="请输入文章标题" required maxlength="20"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">文章分类</label>
                        <div class="col-sm-8 ">
                            <input id="drilldown1" class="form-control" placeholder="请选择分类"
                                   data-toggle="dropdown" readonly="readonly">
                            <input id="parentId" class="hidden" name="catalogId">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="editor" class="col-sm-2 control-label">文章内容</label>
                        <div class="col-sm-8 ">
                            <div name="content" id="editor" style="height:300px;"></div>
                        </div>
                    </div>

                    <%-- <div class="form-group">
                         <label for="isTop" class="col-sm-2 control-label">是否置顶</label>
                         <div class="col-sm-8">
                             <input class="myCheckBox" type="checkbox" name="isTop" id="isTop">
                         </div>
                     </div>--%>
                    <div class="form-group">
                        <div class="col-sm-10 " style="text-align: right;">
                            <button type="submit" class="btn btn-success">发布文章</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

</body>
<script type="text/javascript">
    changeTitle('创建帮助内容');
    var ue;
    $(function () {

        initForm('#createForm', '${ctx}/admin/helparticle/create', function (r) {
            var resp = $.parseJSON(r);
            if (resp.code == 'OK') {
                changeUrl('${ctx}/admin/helparticle');
                topLayer.msg('保存成功', {icon: 1});
            } else {
                topLayer.msg(resp.message, {icon: 2});
            }
        });

        ue = UE.getEditor('editor', {
            serverUrl: _ctx + "/admin/helparticle/editor",
            initialContent: '请输入文章内容',
            elementPathEnabled: false
        });

        $.getJSON('${ctx}/admin/helparticlecatalog/list', function (result) {
            if (result.code == 'OK') {
                fillData(result.body);
            }
        });

    })

    function adjustHeight(val) {
        if (val == 1) {
            $('#abstract').height(200);
        } else {
            $('#abstract').height(54);
        }
    }

    function fillData(data) {
        var param = {
            list: data,
            inParams: {
                pid: "parentId",
                rootId: null,
                id: 'id'
            },
            outParams: {
                children: "list",
                pid: "pid",
                id: 'id'
            },
            sort: {
                orderBy: ["sort"],
                sort: "asc"
            }
        };
        var tree = wg_listToTree(param);
        console.log(tree);
        if (tree.length == 0) {
            tree = [{
                id: -1,
                name: "没有分类，去创建一个吧",
            }]
        }
        console.log(tree);
        $('#drilldown1').drilldownSelect({
            appendValue: false,
            data: tree,
            onSelected: function (event) {
                if ($(event.target).data('id') === -1) {
                    window.location.href = '${ctx}/admin/helparticlecatalog';
                }
                $('#parentId').val($(event.target).data('id'));
                $('#drilldown1').val(event.target.innerHTML);
            }
        });
    }
</script>
</html>
